/*
 * 意见反馈管理
 * @author 曾文
 * @time 2018/9/26
 * @since 1.0.0
 * */
import React from 'react'
import { connect } from 'dva'
import { Form } from 'antd'
import { Link, hashHistory } from 'dva/router'
import FlagBtn from 'widget/FlagBtn/FlagView'
import config from 'config/config'
import { mapStateToProps } from 'utils/view_utils'
import styles from './feedbackListStyle.less'
import ListPage from 'widget/PageTmpl/ListPage'
import { Button } from 'antd/lib/radio';

function detailSkip(type, feedbackId) {
    hashHistory.push({
        pathname: '/home/systemAdmin/feedbackDetail',
        query: { actionType: type, feedbackId }
    });

}
let subElements = JSON.parse(localStorage.getItem('navBar')).subElements
console.log(subElements)
let sle_label = [
    {
        value: '1',
        label: '住房供应链',
    },
    {
        value: '2',
        label: '智美分销'
    },
    // {
    //     value: '3',
    //     label: '置业神器'
    // }
]
function include() {
    // if (subElements.indexOf(50401) > -1) {
    //     return [
    //         {
    //             value: '1',
    //             label: '美的置业云',
    //         }
    //     ]
    // } else {
        return sle_label
    // }
}

const routeView = function ({ dispatch, model, form }) {

    const { resetFields, getFieldDecorator, validateFields, setFieldsValue } = form
    const { modelObj, namespace } = model

    const clickHandler = (e) => {
        //console.log(213123123)
        dispatch({
            type: `${namespace}/xxx`,
            payload: {}
        });
    }
    let pageProps = {
        "ui": {
            "api_url": "admin/feedback/queryList",
            "method": "POST",
            "app": "",
            "params": "",
            "mockData": null,
            btnId: '50401',
            "search_bar": {
                "fields": [
                    // {
                    //     en_name: 'channel',
                    //     zh_name: '平台',
                    //     elem_type: 'Select',
                    //     elem_valid_type: 'string',
                    //     cmpt_items: include()
                    // },
                    //   {
                    //   en_name: 'province',
                    //   zh_name: '省市',
                    //   elem_type: 'Cascader',
                    //   elem_valid_type: 'string',
                    //   cmpt_items: [],//areaList
                    //   split_keys: ['province', 'city'],
                    //   //关联的更改的搜索字段
                    //   related_key: 'businessId',
                    //   //请求地址
                    //   related_req_url: 'admin/estate/list',
                    //   //默认请求
                    //   related_req_param: {
                    //     pageNo: 1,
                    //     pageSize: 1000
                    //   }
                    // },
                    // {
                    //     en_name: 'projectName',
                    //     zh_name: '项目',
                    //     elem_type: 'Input',
                    //     elem_valid_type: 'string',
                    //     // cmpt_items: []
                    // },
                    {
                        en_name: 'mobile',
                        zh_name: '手机号码',
                        elem_type: 'Input',
                        elem_valid_type: 'string',
                    },
                    {
                        en_name: 'date',
                        zh_name: '提交日期',
                        elem_type: "Date",
                        //format: "YYYY-MM-DD HH:mm",
                        double: true,
                        split_keys: ['startTime', 'endTime'],
                        elem_valid_type: "string"
                    },
                ],
                searchHandler: () => { // 自定义搜索按钮回调函数，点击搜索时触发
                    console.log('search click')
                    //dispatch({ type: `${namespace}/updateStore`, payload: { queryList: [1, 2, 3, 4] } })
                    dispatch({ type: `${namespace}/updateStore`, payload: { queryList: modelObj.biz.queryForm } })
                },
                resetHandler: () => { // 自定义重置按钮回调函数，点击重置时触发
                    console.log('reset click')
                    dispatch({ type: `${namespace}/updateStore`, payload: { queryList: {} } })
                },
                searchCallback: params => { // 自定义搜索完成后的后调函数, 搜索完成后触发, 并将本次搜索的参数传入
                    console.log('search finish', params)
                },
            },
            // 数据表格
            "table":
            {
                "status_params": "status=0",
                "status_text": "全部",
                "scroll": { x: 1200 },
                "fields": [//平台  项目  所属城市  问题  手机号码  姓名  提交日期
                    // {
                    //     "en_name": "channel",
                    //     "zh_name": "平台",
                    //     "width": "100",
                    //     render: (a, item, index, d, e, f) => {
                    //         return (
                    //             <span>{{ 1: '美的置业云', 2: '智美分销',4: '置业云APP'}[item.channel] || ''}</span>
                    //         )
                    //     },
                    // },
                    // {
                    //     "en_name": "projectName",
                    //     "zh_name": "项目",
                    //     "placeholder": '支持模糊搜索',
                    //     width: 130,
                    // },
                    // {
                    //     "en_name": "provinceName",
                    //     "zh_name": "所属城市",
                    //     width: 150,
                    //     render: (text, item, index) => {
                    //         return `${item.provinceName || ''}${item.provinceName && item.cityName && ' - ' || ' '}${item.cityName || ''}`
                    //     }
                    // },
                    // {
                    //   "en_name": "accountId",
                    //   "zh_name": "用户ID",
                    // },
                    {
                        "en_name": "content",
                        "zh_name": "问题",
                        width: 300,
                        render: (text, item, index) => {
                            return <div style={{ maxHeight: '60px', overflowY: 'auto' }} dangerouslySetInnerHTML={{ __html: text }}>
                            </div>
                        }
                    },
                    {
                        "en_name": "mobile",
                        "zh_name": "手机号码",
                        width: 130
                    },
                    {
                        "en_name": "name",
                        "zh_name": "姓名",
                        width: 80,
                    },
                    // {
                    //   "en_name": "gender",
                    //   "zh_name": "性别",
                    //   render: (text, item, index) => {
                    //     let txt = ''
                    //     if (item.gender == 1) {
                    //       txt = "男"
                    //     } else {
                    //       txt = '女'
                    //     }
                    //     return <span>{txt}</span>
                    //   }
                    // },

                    {
                        "en_name": "createTime",
                        "zh_name": "提交日期",
                        width: 110,
                        render: (text, row) => {
                            return text.split(' ')[0]
                        }
                    },
                    {
                      "en_name": "edit",
                      "zh_name": "操作",
                      width:60,
                      render: (a, item, index, d, e, f) => {
                        return (
                          <span>
                            <FlagBtn node={<a onClick={() => detailSkip('check', item.feedbackId)}>查看</a>} btnId={'50701'}> </FlagBtn>
                          </span>
                        )
                      },
                    },
                ]
            },
            action_bar: [
                {
                    label: '导出',
                    type: 'primary',
                    onClick: (e, row) => {
                        dispatch({
                            type: `${namespace}/exportFeedback`,
                            payload: {}
                        })
                    }
                },
            ],
        },
    }
    if (!!modelObj.biz) {
        pageProps.biz = modelObj.biz
        pageProps.biz.syncBackCbf = (biz) => {
            console.log(biz)
            dispatch({
                type: `${namespace}/updateStore`,
                payload: { biz }
            })
        }
    }

    return (
        <div onClick={e => clickHandler(e)}>
            <ListPage pageProps={pageProps} />
        </div>
    )
}
export default connect(mapStateToProps)(Form.create()(routeView))
